import Duck from 'extensible-duck'
import produce from 'immer'

const initState = {
  staticValues: {

  },
  dynamicValue: {
    polygon: {
      isEditHole: false,
    },
  },
}

export default new Duck({
  namespace: 'label',
  store: 'editInfo',
  types: ['SET_EDIT_LABEL_ID', 'PAINT_POINT', 'RECIVE_POINT'],
  initialState: initState,
  reducer: produce((draft, action, duck) => {
    switch (action.type) {
      case duck.types.SET_EDIT_LABEL_ID:
        draft.dynamicValue.editLabelId = action.id
        break
      default:
        break
    }
  }),
  selectors: {
    editLabelId: state => state.editInfo.dynamicValue.editLabelId,
    isEditPolygonHole: state => state.editInfo.dynamicValue.polygon.isEditHole,
  },
  creators: duck => ({
    actionSetEditLabelId: id => ({ type: duck.types.SET_EDIT_LABEL_ID, id }),
    actionPaintPoint: (x, y) => ({ type: duck.types.PAINT_POINT, x, y }),
    actionRecivePoint: (x, y) => ({ type: duck.types.RECIVE_POINT, x, y }),
  }),
})
